#pragma once
#include "SharedMemory.hpp"
#include <functional>
#include <vector>
#include <map>
#include <mutex>

class MemLink {
public:
    bool init(const std::string& devicePath);
    int allocChannel(ChannelPermission perm);
    void freeChannel(int channelId);
    bool write(int channelId, const std::vector<uint8_t>& data);
    void onData(int channelId, std::function<void(const std::vector<uint8_t>&)> callback);
    void run();
    void shutdown();

private:
    SharedMemory* shm_ = nullptr;
    int fd_ = -1;
    std::map<int, std::function<void(const std::vector<uint8_t>&)>> callbacks_;
    std::mutex alloc_mutex_;
};
